package com.liang.design;

import org.itstack.demo.design.HandlerInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lsm
 * @ClassName LoginSsoDecorator.java
 * @Description TODO
 * @createTime 2023年12月04日 20:22:00
 */
public class LoginSsoDecorator extends SsoDecorator{

    private Logger logger = LoggerFactory.getLogger(LoginSsoDecorator.class);
    private static Map<String, String> authMap = new ConcurrentHashMap<String, String>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }

    public LoginSsoDecorator(HandlerInterceptor handlerInterceptor) {
        super(handlerInterceptor);
    }

    @Override
    public boolean preHandle(String request, String response, Object handler) {
        boolean success = super.preHandle(request, response, handler);
        if (!success) return false;
        String uid = request.substring(8);
        String method = authMap.get(uid);
        logger.info("模拟单点登录⽅方法访问拦截校验： {} {}", uid, method);
        // 模拟⽅方法校验
        return "queryUserInfo".equals(method);
    }
}
